#ifndef _CONFIGGROUP_H
#define _CONFIGGROUP_H

#include <string>
#include <list>
#include <vector>
#include <map>

#include <iostream>
#include <fstream>

class Config;
class Variant;

class ConfigGroup
{
	friend class Config;
	public:
		virtual ~ConfigGroup();

		bool exists();
		bool isEmpty();
		std::string name();
		ConfigGroup* parent();
		Config& config();

		bool hasGroup(const std::string& name);
		void deleteGroup(const std::string& name);
		std::list<std::string> groupList();
		void deleteAll();

		std::list<std::string> keyList();
		bool hasKey(const std::string& key);
		void deleteEntry(const std::string& name);
		std::map<std::string, Variant*>& entryMap();

		int readEntry(const std::string& key, const int& aDefault);
		float readEntry(const std::string& key, const float& aDefault);
		std::string readEntry(const std::string& key, const std::string& aDefault);
		std::vector<int>
      readEntry(const std::string& key, const std::vector<int>& aDefault);
		std::vector<float> readEntry(const std::string& key, const std::vector<float>& aDefault);
		std::vector<std::string> readEntry(const std::string& key, const std::vector<std::string>& aDefault);

		void writeEntry(const std::string& key, const int& value);
		void writeEntry(const std::string& key, const float& value);
		void writeEntry(const std::string& key, const std::string& value);
		void writeEntry(const std::string& key, const std::vector<int>& value);
		void writeEntry(const std::string& key, const std::vector<float>& value);
		void writeEntry(const std::string& key, const std::vector<std::string>& value);

		ConfigGroup& operator[](const std::string& groupName);

	protected:
		ConfigGroup(Config& parent, const std::string& groupName);
		ConfigGroup(ConfigGroup& parent, const std::string& groupName);
		void sync(std::fstream& istream);

		Config& m_config;
		ConfigGroup* m_parent;
		std::string m_name;
		bool m_exists;
		std::map<std::string, ConfigGroup*> m_groups;
		std::map<std::string, Variant*> m_entries;
};

#endif
